package job.gfp.ranks.base;

public enum ValueType {

    DOUBLE {
        @Override
        public String merge(ValueMerger merger, String a, String b) {
            double x = Double.parseDouble(a);
            double y = Double.parseDouble(b);
            switch (merger) {
            case ADD:
                return String.valueOf(x + y);
            case MAX:
                return String.valueOf(Math.max(x, y));
            default:
                throw new RuntimeException();
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public Double parse(String s) {
            return Double.valueOf(s);
        }
    },
    LONG {
        @Override
        public String merge(ValueMerger merger, String a, String b) {
            long x = Long.valueOf(a);
            long y = Long.valueOf(b);

            switch (merger) {
            case ADD:
                return String.valueOf(x + y);
            case MAX:
                return String.valueOf(Math.max(x, y));
            default:
                throw new RuntimeException();
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public Long parse(String s) {
            return Long.valueOf(s);
        }
    };

    public abstract String merge(ValueMerger merger, String a, String b);

    public abstract <T> T parse(String s);

}
